﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Century.Web.Security.Attributes;

using Telerik.Web.Mvc;
using Century.Web.UI.MVC;
using System.Web.Security;
using Century.Model;
using Century.Business.CMS;

namespace Century.Admin.Controllers
{
    [Authorization(Group = "", Name = "Administration")]
    public class UserSiteManagementController : CenturyAdminBaseController
    {
        public UserSiteManagementController(ISiteService siteService) : base(siteService) { }
        //
        // GET: /UserSiteManagement/
        //UserBSO userBSO = new UserBSO();
        //CountrySiteBSO countrySiteBSO = new CountrySiteBSO();
        CenturyDbContext db = new CenturyDbContext();

        public ActionResult Index()
        {
            return View();
        }

        [GridAction]
        public ActionResult GetUserList()
        {
            var model = new GridModel
            {
                Data = db.UserProfiles//.Select(e => new { e.UserId, e.UserName, e.FirstName, e.LastName, e.IsAdministrator })
            };
            return View(model);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult EditUser(int id)
        {
            UserProfile user = db.UserProfiles.Find(id);
            TryUpdateModel(user);
            db.SaveChanges();
            var model = new GridModel
            {
                Data = db.UserProfiles//.Select(e => new { e.UserId, e.UserName, e.FirstName, e.LastName, e.IsAdministrator })
            };
            return View(model);
        }

        //[GridAction]
        //public ActionResult GetCountriesForUser(int userId)
        //{
        //    IEnumerable<Century.Models.Common.CountrySite> countrySites = countrySiteBSO.GetAll();
        //    IEnumerable<Century.Models.Common.CountrySite> userCountries = userBSO.GetCountriesForUser(userId);
        //    var confDetails = countrySites.Select(c =>
        //        new
        //        {
        //            c.Id,
        //            c.Name,
        //            c.Path,
        //            UserHasThisCountrySite = userCountries.Any(a => a.Id == c.Id)
        //        });
        //    return View(new GridModel(confDetails));
        //}

        //public string ChangeUserCountries(int userId, int countrySiteId, bool userHasThisCountry)
        //{
        //    Century.Models.Common.User user = userBSO.Find(c => c.Id == userId, "CountrySites");
        //    Century.Models.Common.CountrySite countrySite = userBSO.FindCountrySite(countrySiteId);
        //    if (userHasThisCountry)
        //    {
        //        user.CountrySites.Add(countrySite);
        //    }
        //    else
        //    {
        //        user.CountrySites.Remove(countrySite);
        //    }
        //    userBSO.Update(user);
        //    return string.Empty;
        //}

    }
}
